#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020/10/25 19:16|19:16
# @Author  : yangdingyi
# @File    : 2020-10-25.845.数组中的最长山脉
# @Software: PyCharm
from tools.my_methods import *


class Solution:
    def longestMountain(self, A: List[int]) -> int:
        left = [1 for i in range(len(A))]
        for i in range(1, len(A)):
            if A[i] > A[i-1]:
                left[i] = max(left[i], left[i-1]+1)

        right = [0 for i in range(len(A))]
        for i in range(len(A)-2, -1, -1):
            if A[i] > A[i+1]:
                right[i] = max(right[i], right[i+1]+1)
        ans = 0
        for i in range(len(A)):
            # ans = max(ans, left[i] + right[i])
            if left[i] > 1 and right[i] > 0:
                ans = max(ans, left[i] + right[i])
        return ans


questions = [
    ([2, 1, 4, 7, 3, 2, 5],),
    ([2, 2, 2],),
    ([2, 3],),
]

work(questions, lambda q: Solution().longestMountain(q[0]))
